package com.lanchewuyou.user.driver.layouts;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.lanchewuyou.user.driver.R;

/**
 * 自定义可伸缩布局，设定button回调,用于易理赔维修界面
 */
public class ExpandLayout extends LinearLayout {
    private Button titleBtn;
    private Button huahenYesBtn, huahenNoBtn, banjinYesBtn, banjinNoBtn, penqiYesBtn, penqiNoBtn;
    private LinearLayout expandLinear;
    boolean isExpand = true;

    CallbackHuaYes callbackHuaYes = null;
    CallbackHuaNo callbackHuaNo = null;
    CallbackBanYes callbackBanYes = null;
    CallbackBanNo callbackBanNo = null;
    CallbackPenYes callbackPenYes = null;
    CallbackPenNo callbackPenNo = null;

    public interface CallbackHuaYes {
        public void onClickHuaYes(String title);
    }

    public void setClickHuaYes(CallbackHuaYes clickHuaYes) {
        callbackHuaYes = clickHuaYes;
    }

    public interface CallbackHuaNo {
        public void onClickHuaNo(String title);
    }

    public void setClickHuaNo(CallbackHuaNo clickHuaNo) {
        callbackHuaNo = clickHuaNo;
    }

    public interface CallbackBanYes {
        public void onClickBanYes(String title);
    }

    public void setClickBanYes(CallbackBanYes clickBanYes) {
        callbackBanYes = clickBanYes;
    }

    public interface CallbackBanNo {
        public void onClickBanNo(String title);
    }

    public void setClickBanNo(CallbackBanNo clickBanNo) {
        callbackBanNo = clickBanNo;
    }

    public interface CallbackPenYes {
        public void onClickPenYes(String title);
    }

    public void setClickPenYes(CallbackPenYes clickPenYes) {
        callbackPenYes = clickPenYes;
    }

    public interface CallbackPenNo {
        public void onClickPenNo(String title);
    }

    public void setClickPenNo(CallbackPenNo clickPenNo) {
        callbackPenNo = clickPenNo;
    }

    public ExpandLayout(Context context) {
        super(context);
    }

    public ExpandLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.expand_layout, this);
        expandLinear = (LinearLayout) findViewById(R.id.linear_expand);
        expandLinear.setVisibility(View.GONE);
        titleBtn = (Button) findViewById(R.id.carinfor_title_btn);
        titleBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isExpand) {
                    titleBtn.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.mipmap.up_1, 0);
                    expandLinear.setVisibility(View.VISIBLE);
                    isExpand = false;
                } else {
                    titleBtn.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.mipmap.down_1, 0);
                    expandLinear.setVisibility(View.GONE);
                    isExpand = true;
                }
            }
        });
        //设定划痕维修button回调
        huahenYesBtn = (Button) findViewById(R.id.huahen_yes_btn);
        huahenYesBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                callbackHuaYes.onClickHuaYes(titleBtn.getText().toString());
            }
        });

        //设定划定不修回调
        huahenNoBtn = (Button) findViewById(R.id.huahen_no_btn);
        huahenNoBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                callbackHuaNo.onClickHuaNo(titleBtn.getText().toString());
            }
        });

        banjinYesBtn = (Button) findViewById(R.id.banjin_yes_btn);
        banjinYesBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                callbackBanYes.onClickBanYes(titleBtn.getText().toString());
            }
        });
        banjinNoBtn = (Button) findViewById(R.id.banjin_no_btn);
        banjinNoBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                callbackBanNo.onClickBanNo(titleBtn.getText().toString());
            }
        });

        penqiYesBtn = (Button) findViewById(R.id.penqi_yes_btn);
        penqiYesBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                callbackPenYes.onClickPenYes(titleBtn.getText().toString());
            }
        });
        penqiNoBtn = (Button) findViewById(R.id.penqi_no_btn);
        penqiNoBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                callbackPenNo.onClickPenNo(titleBtn.getText().toString());
            }
        });


    }


    public void setTitleText(String titleText) {
        titleBtn.setText(titleText);
    }

    //0表示按下
    public void setHuaYesBtnPress(int btnPress) {
        switch (btnPress) {
            case 0:
                huahenYesBtn.setTextColor(getResources().getColor(R.color.white));
                huahenYesBtn.setBackgroundColor(getResources().getColor(R.color.buttonpressblue));
                break;
            case 1:
                huahenYesBtn.setTextColor(getResources().getColor(R.color.textgrey));
                huahenYesBtn.setBackgroundColor(getResources().getColor(R.color.white));
                break;
            default:
                break;
        }

    }

    public void setHuaNoBtnPress(int btnPress) {
        switch (btnPress) {
            case 0:
                huahenNoBtn.setTextColor(getResources().getColor(R.color.white));
                huahenNoBtn.setBackgroundColor(getResources().getColor(R.color.buttonpressred));
                break;
            case 1:
                huahenNoBtn.setTextColor(getResources().getColor(R.color.textgrey));
                huahenNoBtn.setBackgroundColor(getResources().getColor(R.color.white));
                break;
            default:
                break;
        }

    }

    public void setBanYesBtnPress(int btnPress) {
        switch (btnPress) {
            case 0:
                banjinYesBtn.setTextColor(getResources().getColor(R.color.white));
                banjinYesBtn.setBackgroundColor(getResources().getColor(R.color.buttonpressblue));
                break;
            case 1:
                banjinYesBtn.setTextColor(getResources().getColor(R.color.textgrey));
                banjinYesBtn.setBackgroundColor(getResources().getColor(R.color.white));
                break;
            default:
                break;
        }
    }

    public void setBanNoBtnPress(int btnPress) {
        switch (btnPress) {
            case 0:
                banjinNoBtn.setTextColor(getResources().getColor(R.color.white));
                banjinNoBtn.setBackgroundColor(getResources().getColor(R.color.buttonpressred));
                break;
            case 1:
                banjinNoBtn.setTextColor(getResources().getColor(R.color.textgrey));
                banjinNoBtn.setBackgroundColor(getResources().getColor(R.color.white));
                break;
            default:
                break;
        }
    }

    public void setPenYesBtnPress(int btnPress) {
        switch (btnPress) {
            case 0:
                penqiYesBtn.setTextColor(getResources().getColor(R.color.white));
                penqiYesBtn.setBackgroundColor(getResources().getColor(R.color.buttonpressblue));
                break;
            case 1:
                penqiYesBtn.setTextColor(getResources().getColor(R.color.textgrey));
                penqiYesBtn.setBackgroundColor(getResources().getColor(R.color.white));
                break;
            default:
                break;
        }
    }

    public void setPenNoBtnPress(int btnPress) {
        switch (btnPress) {
            case 0:
                penqiNoBtn.setTextColor(getResources().getColor(R.color.white));
                penqiNoBtn.setBackgroundColor(getResources().getColor(R.color.buttonpressred));
                break;
            case 1:
                penqiNoBtn.setTextColor(getResources().getColor(R.color.textgrey));
                penqiNoBtn.setBackgroundColor(getResources().getColor(R.color.white));
                break;
            default:
                break;
        }
    }
}
